#pragma once
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <log/log.h>
#include "ion.h"
#include "Device.h"

#define DEV "/dev/ion"
#define ION_BUFFER_LEN 4096
#define MAX_HEAP_COUNT ION_HEAP_TYPE_CUSTOM

namespace android::wmark
{

    struct ion_buffer_info
    {
        int ionfd;
        int buffd;
        unsigned int heap_type;
        unsigned int flag_type;
        unsigned long heap_size;
        unsigned long buflen;
        unsigned char *buffer;
    };
    class IonDev : public Device
    {
    public:
        IonDev(/* args */) : Device(DEV) {}
        ~IonDev() {}

        // 创建 1 个 dmabuf
        int createBuf(struct ion_buffer_info &info, unsigned long len);

        int ionExportBufferFd(struct ion_buffer_info *ion_info);
        int ionImportBufferFd(struct ion_buffer_info *ion_info);
        void ionCloseBufferFd(struct ion_buffer_info *ion_info);
    };
}